﻿@{
    Layout = null;
}
@RenderPage("~/Views/Samples/Generic/PageDeclaration.cshtml", new
{
    CodeBehind = "Default",
    Inherits = ViewBag.Project.Name + "." + ViewBag.Sample.Path + "Default",
    Title = ViewBag.Sample.Name,
    RegisterSlickUpload = true,
    Model = "Krystalware.SlickUpload.UploadSession"
})
@SampleHelper.BeginSection("head")
<script type="text/javascript">
    function cancelUpload()
    {
        kw("@SampleHelper.ResolveId("slickUpload")").cancel();
    }

    function onSessionStarted(data)
    {
        document.getElementById("@SampleHelper.ResolveId("uploadButton")").style.display = "none";
        document.getElementById("@SampleHelper.ResolveId("cancelButton")").style.display = "block";
    }
        
    function onBeforeSessionEnd(data)
    {
        document.getElementById("@SampleHelper.ResolveId("cancelButton")").style.display = "none";
    }
</script>

<style type="text/css">
    /* hide initially  */
    .su-fileselector, .su-folderselector, .su-filelisttemplate, .su-uploadprogressdisplay
    {
        display: none;
        zoom:1;
    }
    
    /* fileselector cursor, link color */
    .su-fileselector, .su-fileselector *, .su-folderselector, .su-folderselector *
    {
        color:blue;
        cursor:pointer;
    }

    /* hover links */
    a
    {
        text-decoration:none
    }
    
    a:hover, .su-hover a
    {
        text-decoration:underline;
    }
</style>
@SampleHelper.EndSection()
@SampleHelper.BeginSection("content", true)
    @SampleHelper.BeginForm("uploadForm", "Index", "Home", "multipart/form-data")
    @if (ViewBag.Project.IsAspNetAjax)
    {
        <asp:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true">
        </asp:ScriptManager>               
        @:<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
            @:<ContentTemplate>
    }

    @{
        Dictionary<string, string> attributes = new Dictionary<string, string>()
                            {
                                { "Id", "\"slickUpload\"" },
                                { "FileSelectorStyle", "\"float:left;padding-right:1em\"" },
                                { "FileListStyle", "\"clear:both\"" },
                                { "UploadProgressDisplayStyle", "\"clear:both\"" },
                                { "Style", "\"overflow: hidden; zoom: 1\"" },
                                { "UploadProfile", "\"quickStart\"" },
                                { "OnClientUploadSessionStarted", "\"onSessionStarted\"" },
                                { "OnClientBeforeSessionEnd", "\"onBeforeSessionEnd\"" }
                            };

        if (ViewBag.Project.ViewEngine == ViewEngine.WebForms && ViewBag.Project.Language == CodeLanguage.Cs)
        {
            attributes["OnUploadComplete"] = "\"slickUpload_UploadComplete\"";
        }
        if (ViewBag.Project.ViewEngine == ViewEngine.Mvc || ViewBag.Project.ViewEngine == ViewEngine.Razor)
        {
            attributes["ShowDropZoneOnDocumentDragOver"] = "true";
            attributes["AutoUploadOnSubmit"] = "true";
            attributes["UploadFormId"] = "\"uploadForm\"";

            SampleHelper.RewriteHtmlAttributes(attributes, "", ViewBag.Project.Language);
            SampleHelper.RewriteHtmlAttributes(attributes, "FileSelector", ViewBag.Project.Language);
            SampleHelper.RewriteHtmlAttributes(attributes, "FileList", ViewBag.Project.Language);
            SampleHelper.RewriteHtmlAttributes(attributes, "UploadProgressDisplay", ViewBag.Project.Language);
        }                                     
    }
                       @SampleHelper.RenderComponent("SlickUpload", attributes, null, new
                  {
                      SelectorTemplate = (Func<object, HelperResult>)(
                          @<text>
                                    <a href="javascript:;">Add files</a>
                                    </text>),
                      SelectorFolderTemplate = (Func<object, HelperResult>)(
                          @<text>
                                    <a href="javascript:;">Add folder</a>
                                    </text>),
                      FileItemTemplate = (Func<object, HelperResult>)(
                          @<text>
                                        @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.FileName" })
                                        &ndash;
                                        @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.FileSize" }, null, "(calculating)")
                                        @SampleHelper.RenderComponent("FileListRemoveCommand", null, new { href = "\"javascript:;\"" }, "[x]")
                                        @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.ValidationMessage" }, new { style = "\"color:#f00\"" })
                                    </text>),
                      ProgressTemplate = (Func<object, HelperResult>)(
                          @<text>
                                        <div>
                                            Uploading @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.FileCount" }) file(s),
                                            @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.ContentLengthText" }, null, "(calculating)").
                                        </div>
                                        <div>
                                            Currently uploading: @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.CurrentFileName" })
                                            file @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.CurrentFileIndex" })
                                            of @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.FileCount" }).
                                        </div>
                                        <div>
                                            Speed: @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.SpeedText" }, null, "(calculating)")
                                        </div>
                                        <div>
                                            @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.TimeRemainingText" }, null, "(calculating)")
                                        </div>
                                        <div style="border:1px solid #008800; height: 1.5em; position: relative;">
                                            @SampleHelper.RenderComponent("UploadProgressBar", null, new { style = "\"background-color:#00ee00;width:0; height:1.5em;\"" })
                                            <div style="text-align: center; position: absolute; top: .15em; width: 100%;">
                                                @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.PercentCompleteText" }, null, "(calculating)")
                                            </div>
                                        </div>
                                    </text>)
                  })
                            @if (ViewBag.Project.ViewEngine != ViewEngine.WebForms)
                            {
                            @SampleHelper.RenderComponent("KrystalwareScriptRenderer")
                            }                            
                            <hr />
                            @if (ViewBag.Project.ViewEngine == ViewEngine.WebForms)
                            {
                            <p>
                                <asp:Button Text="Upload" id="uploadButton" runat="server" />
                                <asp:Button Text="Cancel" id="cancelButton" runat="server" style="display:none" onclientclick="cancelUpload();return false;" />
                            </p>
                            <p><asp:Label Id="uploadResult" runat="server" /></p>
                            <asp:Repeater id="uploadFileList" runat="server" enableviewstate="false">
                                <HeaderTemplate><ul></HeaderTemplate>
                                <ItemTemplate><li><%# DataBinder.Eval(Container.DataItem, "ClientName")%></li></ItemTemplate> 
                                <FooterTemplate>@Html.Raw("</ul>")</FooterTemplate>
                            </asp:Repeater>
                            }
                            else
                            {
                                <p>
                                    <input type="submit" value="Upload" id="uploadButton" />
                                    <input type="button" value="Cancel" id="cancelButton" style="display:none" onclick="cancelUpload()" />
                                </p>
                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("if (Model != null) {", "If Not Model Is Nothing Then"), true)
                        <text>
                        @SampleHelper.VaryByViewEngine(null, null, "<text>")Upload Result: @SampleHelper.VaryByViewEngine(null, null, "</text>")</text>@SampleHelper.RenderStatement("Model.State.ToString()")

                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("if (Model.State == UploadState.Error) {", "If Model.State = UploadState.Error Then"), true)
                        
                        <text><br /><br />@SampleHelper.VaryByViewEngine(null, null, "<text>")
                        Message: @SampleHelper.VaryByViewEngine(null, null, "</text>")</text>@SampleHelper.RenderStatement("Model.ErrorSummary")

                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "End If"), true)                                
                        <ul>
                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("foreach (UploadedFile file in Model.UploadedFiles) {", "For Each file As UploadedFile In Model.UploadedFiles"))
                        <li>
                            @SampleHelper.RenderStatement("file.ClientName")
                        </li>
                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "Next file"), true)
                        </ul>
                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "End If"), true)                                
                            }

@if (ViewBag.Project.IsAspNetAjax)
{
            @:</ContentTemplate>
        @:</asp:UpdatePanel>            
}        
    @SampleHelper.EndForm()
@SampleHelper.EndSection(true)